<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Models\Traits\Filters;
use Carbon\Carbon;

class EDealLog extends Model
{
    use Filters;

    protected $table = 'e_deal_log';

    protected $casts = [
        'money' => 'float',
    ];

    protected static function add_log($user_id,$to_user_id,$money,$status,$comment,$type)
    {
        EDealLog::insert([
            'user_id' =>$user_id,
            'to_user_id' =>$to_user_id,
            'money' =>$money,
            'status' =>$status,
            'comment' =>$comment,
            'type' =>$type?$type:0,
            'created_at' =>Carbon::now(),
            'updated_at' =>Carbon::now(),
        ]);
    }

    public function myEmoney()
    {
        $status = ($this->status == 1)?'+':'-';

        return [
            'id' => $this->id,
            'comment' => $this->comment,
            'created_at' => $this->created_at->toDateString(),
            'money' => $status.$this->money,
        ];
    }


}
